home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-27 | 6.0 KB | 208 lines | [TEXT/MACA] |
- need ctl
-
- :CLASS popUps <super Control 4 <indexed
-
- \ late bound for subclasses to work - note that there can be no instances
- \ of this class..otherwise HANDLE: is recursive
- :M HANDLE: handle: [ ^base ] ;M
-
- :M CTLHANDLE: get: ctlhndl ;M
-
- :M GETCTLTITLE: ( -- addr len) ^base getTitle: control ;M
-
- \ ( cfa0...cfaN resid -- ) put resid and handlers in menu
- :M PUT: put: resId ^base put: array ;M
-
- :M PUTITEM: put: super ;M
-
- :M GETITEM: ( -- item) get: super ;M
-
- :M EXEC: ( part# --)
- IF getItem: self -> mitem
- ^base -> theMenu get: resID -> menuID
- mitem -dup IF 1- at: self execute exec: action THEN
- get: super put: myValue
- THEN ;M
-
- \ ( item# -- addr len ) get string for item #
- :M GET: ( item -- addr len ) handle: self swap makeInt
- buf255 +base call GetItem buf255 count ;M
-
- :M GETTITLE: ( -- addr len) handle: self >ptr 14 + count ;M
-
- :M GETNAME: ( -- addr len) getItem: self get: self ;M
-
- :M GETMAXVAL: ( -- n) word0 ctlHandle: self call getCtlMax i->l ;M
- :M SETMAXVAL: ( n __) ctlHandle: self swap makeint call setCtlMax ;M
-
- \ ( addr len -- ) Append a menu item
- :M ADD: Str255 handle: self ?new swap call AppendMenu
- getMaxVal: self 1+ setMaxVal: self ;M
-
- \ ( ind --) remove a menu item
- :M REMOVE: ( ind --) handle: self swap makeint call delMenuItem
- getMaxVal: self 1- setMaxVal: self ;M
-
- :M DELETE: remove: self ;M
-
- \ ( addr len item# -- ) replace menu item string, but don't redraw
- :M (SET): alive: [ obj: myWindow ]
- IF >r str255 >r handle: self ?new
- r> r> swap >r makeInt r> call SetItem
- ELSE 2drop drop
- THEN ;M
-
- \ ( addr len item# -- ) replace menu item string and draw menu
- :M SET: (set): self alive: [ obj: myWindow ]
- IF draw: super THEN ;M
-
- :M INSERTITEM: { addr len item# -- }
- handle: self addr len str255 item# makeint call InsMenuItem draw: self ;M
-
- :M (REDRAW): ( item --) dup 0= swap getItem: self = or IF draw: [ obj: myWindow ] THEN ;M
-
- \ ( item# -- ) Enable a menu item
- :M ENABLE: { item -- } handle: self item makeInt call EnableItem
- item (redraw): self ;M
-
- \ ( item# -- ) Grey and disable an item
- :M DISABLE: { item -- } handle: self item makeInt call DisableItem
- item (redraw): self ;M
-
- \ return the number of items in the menu
- :M MITEMS: word0 handle: self call countMItems i->l ;M
-
- :M CHECKED?: ( item -- b) ^base get: control = ;M
-
- :M CLASSINIT: nullcfa fill: super nullcfa put: action ;M
-
- ;CLASS
-
-
- :CLASS popUpMenu <super popUps
-
- rect bounds
- int valueParm
-
- :M HANDLE: ptr: ctlhndl 28 + @ -base @ -base @ ;M
-
- :M PUTRECT: put: bounds ;M
-
- \ *** next three methods apply to the Title box, not the popup ***
-
- \ 0=left;1=center;255=right
- :M JUSTIFY: ( n --) get: valueParm $ ff00 and or put: valueParm ;M
-
- \ $100=bold;$200=italic;$400=underline;$800=outline;$1000=shadow
- :M FACE: ( n --) get: valueParm $ e0ff and or put: valueParm ;M
-
- \ $2000=condense;$4000=extend;$8000=nostyle
- :M STYLE: ( n --) get: valueParm $ 1fff and or put: valueParm ;M
-
- \ build a popup; procid is set to 1=fixedwidth;4=addresmen;8=useWFont
- :M NEW: { x y addr len theWind \ tWid -- }
- theWind saveFont
- get: procID 8 and 0=
- IF 0 tFont 12 tSize THEN addr len tWidth -> tWid \ width of title
- 0 abs: theWind Abs: bounds addr len str255
- w 256 int: valueParm int: resId twid makeint 1008 get: procId +
- makeInt ^base
- call NewControl put: ctlhndl
- ^base get: ctlhndl set-ctl-obj
- theWind put: myWindow theWind restFont ;M
-
- :M GETNEW: { \ theWind -- } get: myWindow -> theWind
- theWind 0= classerr" 190 theWind saveFont
- 0 int: resID theWind +base call getNewControl dup 0= classerr" 170
- put: ctlhndl
- ^base get: ctlhndl set-ctl-obj
- get: myValue ^base put: control theWind restFont ;M
-
- ;CLASS
-
-
- \ Example:
- \ ctlwind suz
- \ " .rsrc" openresfile
- \
- \ 5 popupmenu bob
- \ 100 50 160 69 putrect: bob
- \ 128 putresid: bob 8 init: bob
- \ example: suz
- \ 100 50 " myTitle:" suz new: bob
- \
- \ : one mitem home . ;
- \ 'c one fill: bob
- \ NB. When using PopUpDlgMenus in SaveDlg objects, know that the fill:
- \ method does not fill the instance variable 'myValue' of the control
- \ object. This means that even though the popup looks correct, if the
- \ user doesn't click in the menu, the ivar will not be filled. So access
- \ of the popup value by the getItem: method after the dialog is closed
- \ will not yield the correct number. For right now, must initialize each
- \ popup to the stored value of the saveDlg parameters by hand.
-
- :CLASS popUpDlgMenu <super popUps
-
- int itemNo
-
- :M ITEMNo: ( -- n) get: itemNo ;M
- :M PUTITEMNo: ( n --) put: itemNo ;M
-
- \ returns handle to the control object, not the menu
- \ also, be careful...need to putItemNo: at compile time
- :M CTLHANDLE: ( -- hndl) get: itemNo dup 0= classerr" 191
- handle: [ obj: myWindow ] dup put: ctlhndl ;M
-
- :M PUTITEM: ( -- n) alive: [ obj: myWindow ]
- IF ctlHandle: self swap makeint call SetCtlValue
- ELSE put: myValue
- THEN ;M
-
- :M HANDLE: ctlHandle: self >ptr 28 + @ -base @ -base @ ;M
-
- :M EXECACTION: handle: self drop get: itemNo get: [ obj: myWindow ] putItem: self
- true exec: self returnToModal ;M
-
- :M SETITEM: ( --) ctlHandle: self drop getItem: self putItem: self ;M
-
- :M GETNAME: { \ myMenu -- addr len } alive: [ obj: myWindow ]
- IF setItem: self getItem: self get: self
- ELSE 1 heap> menu -> myMenu get: resID putResID: myMenu getnew: myMenu
- get: myValue get: myMenu
- str255 -base count
- release: myMenu dispose> myMenu
- THEN ;M
-
- ;CLASS
-
- \ Example:
- \ 3 savedlg bob1
- \ 402 putresid: bob1
- \ " .rsrc" openresfile
- \
- \ 5 popUpDlgMenu suz1
- \ 402 putresid: suz1
- \ bob1 putWindow: suz1
- \
- \ 2 putItemNo: suz1
- \
- \ : uu " .rsrc" openresfile getnew: bob1 modal: bob1 ;
- \
- \ 'c returnToModal 2 to: bob1
- \
- \ 0 value huh
- \ : ll handle: suz1 drop get: theItem get: bob1 putItem: suz1
- \ true exec: suz1 returnToModal ;
- \ : ll execAction: suz1 ;
- \ : dosave save: bob1 closer ;
- \ 'c dosave 1 to: bob1
- \ 'c ll 2 to: bob1
- \
- \ : one1 1 ++> huh ;
- \ : two 2 ++> huh ;
- \ : three 3 ++> huh ;
- \ : four 4 ++> huh ;
- \ : five 5 ++> huh ;
- \
- \ 5 'cfas one1 two three four five 400 put: suz1
-